#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace pong
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        ContentManager content;

        cObjetos oEsenario;
        cFhumano oFichaHUM;
        cBola oBola;
        cFia oFichaCPU;

        SpriteFont _font ;
        static SpriteBatch SpriteBatch;
            
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            content = new ContentManager(Services);
            oBola = new cBola(this);
            oEsenario = new cObjetos(this);
            
            oFichaCPU = new cFia(this, oBola,9);
            oFichaHUM = new cFhumano(this,oBola,-9);
                        
            //this.graphics.GraphicsDevice

            //sFuente = new SpriteFont(this);
        }


        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            oFichaCPU.Initialize(1, 3, 3);
            oFichaHUM.Initialize(0.5f, 3, 3);
            oEsenario.Initialize(1.0f);
            oBola.Initialize(1, 1,oFichaHUM, oFichaCPU);
            
            base.Initialize();
        }


        /// <summary>
        /// Load your graphics content.  If loadAllContent is true, you should
        /// load content from both ResourceManagementMode pools.  Otherwise, just
        /// load ResourceManagementMode.Manual content.
        /// </summary>
        /// <param name="loadAllContent">Which type of content to load.</param>
        protected override void LoadGraphicsContent(bool loadAllContent)
        {
            Console.Out.WriteLine("game LoadGraphicsContent");

            if (loadAllContent)
            {
                SpriteBatch = new SpriteBatch(this.graphics.GraphicsDevice);
                oFichaHUM.load(content, "data//caja_3x3x1");
                oFichaCPU.load(content, "data//caja_3x3x1");
                oEsenario.load(content, "data//caja_05");
                oBola.load(content, "data//bola_x1");
                _font = content.Load<SpriteFont>("sFuente");
                cCamara.Initialize(new Vector3(0, 40, 0), new Vector3(0, 0, 0));
                // TODO: Load any ResourceManagementMode.Automatic content
            }

            // TODO: Load any ResourceManagementMode.Manual content
        }


        /// <summary>
        /// Unload your graphics content.  If unloadAllContent is true, you should
        /// unload content from both ResourceManagementMode pools.  Otherwise, just
        /// unload ResourceManagementMode.Manual content.  Manual content will get
        /// Disposed by the GraphicsDevice during a Reset.
        /// </summary>
        /// <param name="unloadAllContent">Which type of content to unload.</param>
        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent)
            {
                // TODO: Unload any ResourceManagementMode.Automatic content
                content.Unload();
            }

            // TODO: Unload any ResourceManagementMode.Manual content
        }


        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            Console.Out.WriteLine("game Update");
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here

            cCamara.update(oFichaHUM.Posicion);
            oFichaHUM.Update(gameTime);
            oBola.Update(gameTime);
            oFichaCPU.Update(gameTime);
            oEsenario.Update(gameTime);
            base.Update(gameTime);
        }


        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            Console.Out.WriteLine("game Draw");

            graphics.GraphicsDevice.Clear(Color.Black);
//            float aspectRatio = cCamara.ratio;
//            Matrix world = cCamara.world;
//            Matrix view = cCamara.view;
//            Matrix projection = cCamara.projection;
            oFichaHUM.Draw();
            oFichaCPU.Draw();
            oEsenario.Draw();
            oBola.Draw();
            SpriteBatch.Begin();
            SpriteBatch.DrawString(_font, cCamara.posicion.X.ToString(), new Vector2(10, 10), Color.Red);
            SpriteBatch.DrawString(_font, cCamara.posicion.Y.ToString(), new Vector2(10, 30), Color.Red);
            SpriteBatch.DrawString(_font, cCamara.posicion.Z.ToString(), new Vector2(10, 50), Color.Red);
            SpriteBatch.DrawString(_font, cCamara.angulo.ToString(), new Vector2(10, 70), Color.Red);
            SpriteBatch.End();




            base.Draw(gameTime);
        }
    }
}
